package com.hy.dao.impl;

import com.hy.bean.Department;
import com.hy.dao.DepartmentDao;
import com.hy.utils.DBManager;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class DepartmentDaoimpl implements DepartmentDao {
    private final QueryRunner queryRunner = new QueryRunner();

    @Override
    public Department queryById() {
        return null;
    }

    @Override
    public List<Department> queryAll() {
        Connection connection = null;
        String sql = "select id id,dept_name deptName,parent_id parentId,synopsis synopsis from department";
        try {
            connection = DBManager.getConnection();
            return queryRunner.query(connection, sql, new BeanListHandler<>(Department.class));
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                DbUtils.close(connection);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Override
    public long count(Department department) {
        return 0;
    }

    @Override
    public int insert(Department department) {
        return 0;
    }

    @Override
    public int insertBatch(List<Department> entities) {
        return 0;
    }

    @Override
    public int insertOrUpdateBatch(List<Department> entities) {
        return 0;
    }

    @Override
    public int update(Department department) {
        return 0;
    }

    @Override
    public int deleteById() {
        return 0;
    }
}
